<?php

namespace App\Http\Controllers\CRM;

use App\Http\Controllers\Controller;
use App\Http\Resources\CRM\OrderCollection;
use App\Http\Resources\CRM\OrderResource;
use App\Models\Order;
use App\Models\Store;
use Illuminate\Http\Request;

class OrderController extends Controller
{
    public function getList(Store $store, Request $request)
    {
        $query = $store->orders()->latest()->with([
            'user.role', 'member'
        ]);

        if (!empty($request->status))
            $query->where('status', $request->status);

        return new OrderCollection($query->paginate());
    }

    public function getInfo(Store $store, Order $order)
    {
        $order->load([
            'user.role', 'member',
            'items' => [
                'goods', 'table', 'costRule', 'assistantUser'
            ]
        ]);

        return new OrderResource($order);
    }
}
